import 'package:flutter/material.dart';
import '../../helper/Helper.dart';
import '../../helper/global_config.dart';
import '../../helper/uidata.dart';
import '../../model/report.dart';

class ReportAddPage extends StatefulWidget {
  @override
  ReportAddPage(this.spaceId, this.added);
  final String spaceId;
  final VoidCallback added;
  @override
  ReportAddPageState createState() => new ReportAddPageState();
}

class ReportAddPageState extends State<ReportAddPage> {
  // final TextEditingController c1=new TextEditingController();
  final TextEditingController c2 = new TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  upload(BuildContext context) async {
    if (c2.text == "") return;
    var a = new Report(0, Helper.GetGuid(), widget.spaceId, "", c2.text,
        UIData.CurrentUser!.Guid, Helper.DateTimeNowString());
    var pb1 = await Report.Add(a);
    if (pb1 == true) {
      widget.added();
      Navigator.of(context).pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("添加记录"),
        actions: <Widget>[
          ElevatedButton(
            //  color: Colors.blue,
            //  textColor: Colors.white,
            child: Text("保存"),
            onPressed: () {
              //upLoadImg();
              upload(context);
            },
          )
        ],
      ),
      body: ReportAddBody(context),
    );
  }

  ReportAddBody(BuildContext context) => SingleChildScrollView(
        child: ReportAddFields(context),
      );

  ReportAddFields(BuildContext context) => Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            Container(
              margin: EdgeInsets.all(8.0),
              //color: Colors.white,
              child: TextField(
                maxLines: null,
                controller: c2,
                style:
                    TextStyle(fontSize: 16.0, color: Colors.black, height: 1.5),
                decoration: InputDecoration(
                  hintText: "主要内容",
                ),
              ),
            ),
          ],
        ),
      );
}
